# Contributor: Anjandev Momi <anjan@momi.ca>
# Maintainer: Anjandev Momi <anjan@momi.ca>
pkgname=jami-daemon
pkgver=4.0.0_git20230925
pkgrel=3
_gitrev=f19b0fad9b99181e9a5e5a892ae354d940db2bb2
_pjprojectver=1489db073be280629e41d387c1c2561f20b0bfb3
_dhtnetver=21990ef01887f164a88fd81fa8647cfd92174f1c
pkgdesc="Free and universal communication platform which preserves the users’ privacy and freedoms (daemon component)"
url="https://jami.net"
arch="all !ppc64le !s390x !riscv64 !loongarch64" # no webrtc-audio-processing
license="GPL-3.0-or-later"
makedepends="
	alsa-lib-dev
	asio-dev
	cmake
	eudev-dev
	fmt-dev
	ffmpeg-dev
	gnutls-dev
	jsoncpp-dev
	libarchive-dev
	libgit2-dev
	libsecp256k1-dev
	libupnp-dev
	meson
	msgpack-cxx-dev
	opendht-dev
	pulseaudio-dev
	restinio-dev
	speex-dev
	speexdsp-dev
	sqlite-dev
	webrtc-audio-processing-dev
	yaml-cpp-dev
	zlib-dev
	"
subpackages="$pkgname-dev"
source="$pkgname-$_gitrev.tar.gz::https://git.jami.net/savoirfairelinux/jami-daemon/-/archive/$_gitrev/jami-daemon-$_gitrev.tar.gz
	pjproject-$_pjprojectver.tar.gz.noauto::https://github.com/savoirfairelinux/pjproject/archive/$_pjprojectver/pjproject-$_pjprojectver.tar.gz
	dhtnet-$_dhtnetver.tar.gz.noauto::https://git.jami.net/savoirfairelinux/dhtnet/-/archive/$_dhtnetver/dhtnet-$_dhtnetver.tar.gz
	dhtnet-makefile.patch
	opendht-3.1.6-compat-1.patch
	opendht-3.1.6-compat-2.patch
	"
builddir="$srcdir/$pkgname-$_gitrev"
options="!check" # https://git.jami.net/savoirfairelinux/jami-daemon/-/issues/649

prepare() {
	default_prepare

	cp -v ../pjproject-$_pjprojectver.tar.gz.noauto \
		contrib/tarballs/pjproject-$_pjprojectver.tar.gz
	cp -v ../dhtnet-$_dhtnetver.tar.gz.noauto \
		contrib/tarballs/dhtnet-$_dhtnetver.tar.gz
	mkdir -v contrib/native
}

build() {
	cd contrib/native
	../bootstrap \
		--disable-downloads \
		--disable-all \
		--enable-pjproject \
		--enable-dhtnet
	make DEPS_pjproject= DEPS_dhtnet=pjproject

	cd "$builddir"
	abuild-meson \
		-Dinterfaces=library \
		-Dopensl=disabled \
		-Dportaudio=disabled \
		-Dtests=false \
		-Dpkg_config_path="$builddir/contrib/$(cc -dumpmachine)/lib/pkgconfig" \
		. output
	meson compile -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
}

sha512sums="
0d8591013d1e26c436de593d1ee974bf334acdb70ac2e7e2fab3d1e426bb52b7a2b3c8de21603c5945dd2f7829caf781982c95dcc5efa7fe225aa6ba49f64fbb  jami-daemon-f19b0fad9b99181e9a5e5a892ae354d940db2bb2.tar.gz
4a7cf995827f3d450627f32dbba463593e7ee9e268e6050c12622cae9c5ee8b6f7aadd1897e218b5665f467d89d40608681e56017d3cf817b69ad7348070afc7  pjproject-1489db073be280629e41d387c1c2561f20b0bfb3.tar.gz.noauto
6476fe5aa58532587c1641ebabecf8b5bcfebb22faa229a7b1b60765c3b9f7e8539c7912306fdf677a8661b0152535e54f61163d37ee30eff2f739d2309d14ed  dhtnet-21990ef01887f164a88fd81fa8647cfd92174f1c.tar.gz.noauto
7427f53dc26b9a221584804894ec6a913bed4b78f1f72c44e4502985a1e7d5cac631898889955bd561dfd6ba8bc30fa6869ad0ead76879f6a85505cfcbd0d9d4  dhtnet-makefile.patch
b67f830c6e1f92cfa938cfae155011b2926db1a5fe7fda024bc7923377ff7de6aabad7852aa2b06ffc3e22b9e0ab342b71f4e60e7da5dbdddb9ee6326680be5b  opendht-3.1.6-compat-1.patch
fecd100bac56bf1ddf24ed39384f18bb2996588aff95d6435fba65eb13f069e6770f538e1929d2e8e72f11c3443d68eaaa916b899059026aaff7051382c3f898  opendht-3.1.6-compat-2.patch
"
